package com.fit.pages.employee;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.dao.employee.EmployeeDAO;
import com.fit.entities.Employee;
import com.fit.pages.ErrorPage;

@AdminAccess
public class CreateEmployee {

	@Property
	private Employee employee;

	@InjectPage
	private ErrorPage errorPage;

	@Inject
	private EmployeeDAO employeeDAO;

	Object onSuccess() {
		errorPage.setMessage("");

		if (employeeDAO.save(employee)) {
			errorPage.setMessage("Employee successfully added");
			return errorPage;
		} else {
			errorPage.setMessage("Employee is null");
			return errorPage;
		}

	}

}
